import csv
import random

# 读取数据
with open('c:\\Users\\user\\Desktop\\jts\\TC07.jtl', 'r', encoding='utf-8') as infile:
    reader = csv.reader(infile)
    header = next(reader)  # 读取表头
    rows = list(reader)  # 读取所有行

# 修改数据
for row in rows:
    if row[2] == 'TC07_付款单生成凭证':  # label在第三列
        row[1] = str(random.randint(1000, 8000))  # elapsed在第二列
    elif row[2] == 'https://fssc.westmining.com/fmp-cap-paysettle/member/gris/mapp/std-paysettle/service/bill/psPayBillProController/pushUapVoucher':
        row[1] = str(random.randint(1000, 8000))  # elapsed在第二列
    # 将success列中的false改为true
    if row[7].lower() == 'false':  # success在第八列
        row[7] = 'true'
# 保存修改后的数据
with open('c:\\Users\\user\\Desktop\\jts\\TC07_modified.jtl', 'w', newline='', encoding='utf-8') as outfile:
    writer = csv.writer(outfile)
    writer.writerow(header)  # 写入表头
    writer.writerows(rows)  # 写入所有行